// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ReportAction.java

package com.iphaeton.lms.action.report;

import com.iphaeton.common.helper.Pagination;
import com.iphaeton.common.helper.UserSession;
import com.iphaeton.exception.BusinessException;
import com.iphaeton.lms.business.course.scorm12.ICourseService;
import com.iphaeton.lms.business.organize.IOrganizeService;
import com.iphaeton.lms.business.report.*;
import com.iphaeton.lms.pojo.organize.Organize;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
import org.apache.struts.action.*;
import org.dom4j.io.XMLWriter;

// Referenced classes of package com.iphaeton.lms.action.report:
//            ReportBizSupportAction

public class ReportAction extends ReportBizSupportAction
{

    public ReportAction()
    {
        cal = Calendar.getInstance();
        time = cal.getTime();
        df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        currentTime = df.format(time);
    }

    public ActionForward organizeCourseReport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        daf = (DynaActionForm)form;
        List list = null;
        int uc = 0;
        Organize org = null;
        String id = (String)daf.get("id");
        try
        {
            if(id == null || "".equals(id))
                id = ((UserSession)request.getSession().getAttribute("userSession")).getManageOrgId();
            org = organize.findOrganizeById(id);
            list = report.organizeCourseReport(org.getUrl());
            uc = organize.findAllUser(org, 'a').size();
        }
        catch(BusinessException e)
        {
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("organize", org);
        request.setAttribute("list", list);
        request.setAttribute("uc", new Integer(uc));
        request.setAttribute("cc", new Integer(list.size()));
        return mapping.findForward("organize_course_report");
    }

    public ActionForward organizeCourseChart(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        daf = (DynaActionForm)form;
        String reStr = "";
        String id = (String)daf.get("id");
        String chart = (String)daf.get("chart");
        if(chart.equals("line"))
            reStr = "organize_course_line";
        if(chart.equals("arear"))
            reStr = "organize_course_arear";
        if(chart.equals("verticalbar"))
            reStr = "organize_course_verticalbar";
        try
        {
            if(id == null || "".equals(id))
                id = ((UserSession)request.getSession().getAttribute("userSession")).getId();
            List list = report.organizeCourseChart(id);
            de.laures.cewolf.DatasetProducer categoryData = new OrganizeCourseDSP(list);
            request.setAttribute("categoryData", categoryData);
        }
        catch(BusinessException e)
        {
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        return mapping.findForward(reStr);
    }

    public ActionForward getTreeRoot(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0L);
        org.dom4j.Document doc = null;
        String type = request.getParameter("type");
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String id = userSession.getManageOrgId();
            Organize org = organize.findOrganizeById(id);
            doc = report.getTreeRoot(request.getContextPath(), org, type);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        response.setContentType("text/xml; charset=UTF-8");
        javax.servlet.ServletOutputStream sos = response.getOutputStream();
        XMLWriter writer = new XMLWriter(sos);
        writer.write(doc);
        writer.flush();
        writer.close();
        return null;
    }

    public ActionForward getTree(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0L);
        org.dom4j.Document doc = null;
        String id = request.getParameter("id");
        String type = request.getParameter("type");
        try
        {
            Organize org = organize.findOrganizeById(id);
            if("course".equals(type))
                doc = report.getCourseTree(request.getContextPath(), org);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        response.setContentType("text/xml; charset=UTF-8");
        javax.servlet.ServletOutputStream sos = response.getOutputStream();
        XMLWriter writer = new XMLWriter(sos);
        writer.write(doc);
        writer.flush();
        writer.close();
        return null;
    }

    public ActionForward courseStudyReport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int pageSize = 0x7fffffff;
        int currentPage = 1;
        String sort = request.getParameter("course_sort") != null ? request.getParameter("course_sort") : "";
        String row = request.getParameter("row");
        String courseId = request.getParameter("course_id") != null ? request.getParameter("course_id") : "";
        List list = null;
        try
        {
            String id = ((UserSession)request.getSession().getAttribute("userSession")).getManageOrgId();
            pageInfo = course.courseStudyInfo(id, courseId, sort, row, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            list = course.findPageList(pageInfo);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        request.setAttribute("sort", sort);
        request.setAttribute("course", courseId);
        return mapping.findForward("course_study_report");
    }

    public ActionForward courseStudyChart(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String reStr = "";
        String sort = request.getParameter("course_sort");
        String courseId = request.getParameter("course_id");
        String chart = request.getParameter("chart");
        if(chart.equals("line"))
            reStr = "course_study_line";
        if(chart.equals("arear"))
            reStr = "course_study_arear";
        if(chart.equals("verticalbar"))
            reStr = "course_study_verticalbar";
        try
        {
            String id = ((UserSession)request.getSession().getAttribute("userSession")).getManageOrgId();
            List list = report.courseStudyChart(id, courseId, sort);
            de.laures.cewolf.DatasetProducer categoryData = new CourseStudyDSP(list);
            request.setAttribute("categoryData", categoryData);
        }
        catch(BusinessException e)
        {
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        return mapping.findForward(reStr);
    }

    public ActionForward getCourseTree(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0L);
        org.dom4j.Document doc = null;
        try
        {
            String id = ((UserSession)request.getSession().getAttribute("userSession")).getManageOrgId();
            doc = report.getCourseTree(id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        response.setContentType("text/xml; charset=UTF-8");
        javax.servlet.ServletOutputStream sos = response.getOutputStream();
        XMLWriter writer = new XMLWriter(sos);
        writer.write(doc);
        writer.flush();
        writer.close();
        return null;
    }

    public ActionForward sortCourseTree(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0L);
        org.dom4j.Document doc = null;
        try
        {
            String organize_id = ((UserSession)request.getSession().getAttribute("userSession")).getManageOrgId();
            doc = report.getSortCourseTree(organize_id, id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        response.setContentType("text/xml; charset=UTF-8");
        javax.servlet.ServletOutputStream sos = response.getOutputStream();
        XMLWriter writer = new XMLWriter(sos);
        writer.write(doc);
        writer.flush();
        writer.close();
        return null;
    }

    private static Logger logger;
    private DynaActionForm daf;
    private Pagination pageInfo;
    Calendar cal;
    Date time;
    DateFormat df;
    String currentTime;
    static Class class$0; /* synthetic field */

    static 
    {
        logger = Logger.getLogger(com.iphaeton.lms.action.report.ReportAction.class.getName());
    }
}
